var TaskWatch = function(){

	var twi = new TaskWatchInfo();
	this.expiredTask=null;
	this.search_task_name = new Ext.form.TextField({
		fieldLabel : '任务名称',
		width : 120
	});
	
	this.search_plan_title = new Ext.form.TextField({
		fieldLabel : '计划名称',
		width : 120
	});
	
	this.search_dtStart = new Ext.form.DateField( {
		fieldLabel : '任务派发开始时间',
		format : 'Y-m-d',
		//readOnly : true,
		width : 120
	});

	this.search_dtEnd = new Ext.form.DateField( {
		fieldLabel : '任务派发结束时间',
		format : 'Y-m-d',
		//readOnly : true,
		width : 120
	});
	
	this.search_cmStart = new Ext.form.DateField( {
		fieldLabel : '任务提交开始时间',
		format : 'Y-m-d',
		//readOnly : true,
		width : 120
	});

	this.search_cmEnd = new Ext.form.DateField( {
		fieldLabel : '任务提交结束时间',
		format : 'Y-m-d',
		//readOnly : true,
		width : 120
	});
	
	this.search_planBgStartDate = new Ext.form.DateField( {
		fieldLabel : '计划开始时间',
		format : 'Y-m-d',
		//readOnly : true,
		width : 120
	});

	this.search_planBgEndDate = new Ext.form.DateField( {
		fieldLabel : '计划结束时间',
		format : 'Y-m-d',
		//readOnly : true,
		width : 120
	});
	
	this.search_planEdStartDate = new Ext.form.DateField( {
		fieldLabel : '计划完结开始时间',
		format : 'Y-m-d',
		//readOnly : true,
		width : 120
	});

	this.search_planEdEndDate = new Ext.form.DateField( {
		fieldLabel : '计划完结结束时间',
		format : 'Y-m-d',
		//selectOnFocus : true,
		width : 120
	});
	
	this.taskStatus = new Ext.form.ComboBox( {
		store : new Ext.data.ArrayStore({
        	fields: ['id', 'name'],
        	data: [['','---请选择---'],[0, '草稿'], [1, '下发'], [2, '完成'], [3, '撤销']]
        }),
		fieldLabel : '任务状态',
		mode : 'local',
		displayField : 'name',
		triggerAction : 'all',
		editable : false,
		valueField : 'id',
		typeAhead : true,
		selectOnFocus : true,
		width : 120
	});
	this.taskName = new Ext.form.TextField({
		fieldLabel : '任务名称',
		width : 120
	});
/*	this.taskType = new Ext.form.ComboBox( {
		store : new Ext.data.ArrayStore({
        	fields: ['id', 'name'],
        	data: OMS.TASKORIGINVALUE
        }),
		fieldLabel : '任务类型',
		mode : 'local',
		emptyText:'请选择',
		displayField : 'name',
		triggerAction : 'all',
		editable : false,
		valueField : 'id',
		typeAhead : true,
		selectOnFocus : true,
		width : 120
	});*/
	
	this.taskType = new Ext.form.ComboBox( {
		fieldLabel : '任务来源',
    	width: 120,
		store : new Ext.data.ArrayStore({
        	fields: ['id', 'name'],
        	data: [[-1,'请选择'],[0,'计划'],[1,'会议'],[2,'公文督办'],[3,'厅问题督办'],[4,'厅问题督办'],[6,'提交审核'],[7,'指标下派'],[8,'指标审核'],[9,'指标排查']]
        }),
        value:-1,
        emptyText:'请选择',
        valueField: 'id',
        displayField: 'name',
        editable: false,
        mode: 'local',
        triggerAction: 'all',
        selectOnFocus: true
	});	
	this.taskTypeNew = new Ext.form.ComboBox( {
		fieldLabel : '任务类型',
    	width: 120,
		store : new Ext.data.ArrayStore({
        	fields: ['id', 'name'],
        	data: [['','请选择'],[1,'日常工作'],[2,'专项工作'],[3,'会议'],[4,'培训']]
        }),
        emptyText:'请选择',
        valueField: 'id',
        displayField: 'name',
        editable: false,
        mode: 'local',
        triggerAction: 'all',
        selectOnFocus: true
	});	
	this.finishState = new Ext.form.ComboBox( {
		store : new Ext.data.ArrayStore({
        	fields: ['id', 'name'],
        	data: [['','请选择'],[1, '办理中'], [3, '完成'], [4, '已中止']]
        }),
		fieldLabel : '完成情况',
		mode : 'local',
		displayField : 'name',
		triggerAction : 'all',
		editable : false,
		valueField : 'id',
		typeAhead : true,
		selectOnFocus : true,
		width : 120
	});	
	this.getDeptForExecutor = new Ext.data.JsonStore({
		url : '../task/getBranchInfoForExecutor.form?timesnap=' + Date.parse(new Date()),
		method : 'POST',
		root : 'result',
		fields : ['ID','BRANCHNAME']
	});	
	 this.exeDept = new Ext.form.ComboBox({
	    	fieldLabel:'执行部门',
	    	width: 120,
	        store: this.getDeptForExecutor,
	        emptyText:'请选择',
	        valueField: 'ID',
	        displayField: 'BRANCHNAME',
	        editable: false,
	        mode: 'local',
	        triggerAction: 'all',
	        selectOnFocus: true
	    });
	this.executorName = new Ext.form.TextField({
		fieldLabel : '执行人',
		width : 120
	});
	this.getDept = new Ext.data.JsonStore({
		url : '../task/getBranchInfoForDispatch.form?timesnap=' + Date.parse(new Date()),
		method : 'POST',
		root : 'result',
		fields : ['ID','BRANCHNAME']
	});	
	this.dispatchDept = new Ext.form.ComboBox( {
		fieldLabel : '派发部门',
    	width: 120,
		store : this.getDept,
        emptyText:'请选择',
        valueField: 'ID',
        displayField: 'BRANCHNAME',
        editable: false,
        mode: 'local',
        triggerAction: 'all',
        selectOnFocus: true
	});	
	this.dispatchName = new Ext.form.TextField({
		fieldLabel : '派发人',
		width : 120
	});
	
	this.dispatchTime = new Ext.form.DateField({
		fieldLabel: '派发时间',
		format : 'Y-m-d',
        width:150
	});
	this.dispatchEndTime = new Ext.form.DateField({
		fieldLabel: '到',
		format : 'Y-m-d',
        width:150
	});
	this.finishedStartTime = new Ext.form.DateField({
		fieldLabel: '完成时间',
		format : 'Y-m-d',
        width:150
	});
	this.finishedEndTime = new Ext.form.DateField({
		fieldLabel: '到',
		format : 'Y-m-d',
        width:150
	});
	this.search_form = new Ext.form.FormPanel({
		title:'查询条件',
		collapsible:true,
		width : '1020',
		frame : true,
		labelWidth : 65,
		labelAlign : 'right',
		scope : this,
		buttons : [
		           {text:' 本周完成的任务  ',scope:this,handler:function(){this.expiredTask = 'weekfinished',this.taskStore.load();}},		           
		           {text:' 本月已完成的任务  ',scope:this,handler:function(){this.expiredTask = 'monthfinished',this.taskStore.load();}},
		           {text:' 逾期未完成的任务  ',scope:this,handler:function(){this.expiredTask = 'expired',this.taskStore.load();}},
		           {text:' 下发已完成  ',scope:this,handler:function(){this.expiredTask = 'dispatchFinished',this.taskStore.load();}},
		           {text:' 下发未完成  ',scope:this,handler:function(){this.expiredTask = 'dispatchUnFinished',this.taskStore.load();}},
		           {text:'查询',scope:this,handler:function(){this.expiredTask = 'no',this.taskStore.load();}},
		           {text:'清空',scope:this,handler:function(){this.search_form.getForm().reset();}}],
		items : [{layout:'column',
				  defaults:{layout:'form',columnWidth:0.25},
				  items:[
				         {items:[this.taskType,this.taskName,this.dispatchTime]},
				         {items:[this.exeDept,this.executorName,this.dispatchEndTime]},
				         {items:[this.dispatchDept,this.dispatchName,this.finishedStartTime]},
				         {items:[this.taskTypeNew,this.finishState,this.finishedEndTime]}   
				         ]}]
	});
	
	this.taskStore = new Ext.data.JsonStore({
		url : '../task/watchTaskPlan.form?timesnap=' + Date.parse(new Date()),
		method : 'POST',
		root : 'result',
		scope : this,
		fields : ['TASKTITLE','TASK_TITLE','TASK_CONTENT','TASK_DATE','TASK_COMPLETE_DATE','TASK_FEEDBACK','PLAN_TITLE',
		          'TASK_STATUS','TASK_ORIGIN','TASK_NOTE','TASK_EXECUTOR','EXECUTOR','DIS_NAME','PLAN_START_DATE','PLAN_END_DATE','BRANCHNAME','TASKEXESTATUS'],
		listeners : {
			scope : this,
			beforeload : function(thiz){
				thiz.baseParams = {
					taskName : this.taskName.getValue(),
					executorDept : this.exeDept.value,
					dispatchDept : this.dispatchDept.value,
					taskType : this.taskType.value=='-1'?'':this.taskType.value,
					executor : this.executorName.getValue(),
					dispatchor : this.dispatchName.getValue(),
					dispatchTime : this.dispatchTime.value,
					
					dispatchEndTime:this.dispatchEndTime.value,
					finishedStartTime:this.finishedStartTime.value,
					finishedEndTime:this.finishedEndTime.value,
					taskTypeNew:this.taskTypeNew.getValue(),
					taskExeStauts:this.finishState.getValue(),
					expiredTask:this.expiredTask
				};
			}
		}
	});
	
	this.taskGrid = new Ext.grid.GridPanel({
		scope : this,
		height : 400,
		width : '1020',
	    store : this.taskStore,
		columns : [{header:'任务名称',width:230,dataIndex:'TASK_TITLE'},
		           {header:'任务派发时间',width:150,dataIndex:'TASK_DATE'},
		           {header:'完成时间',width:150,dataIndex:'TASK_COMPLETE_DATE'},
		           {header:'派发人',width:80,dataIndex:'DIS_NAME'},
		           {header:'执行人',width:80,dataIndex:'EXECUTOR'},
		           {header:'执行部门',width:130,dataIndex:'BRANCHNAME'},
		           {header:'任务来源',width:80,dataIndex:'TASK_ORIGIN',renderer:function(value){return OMS.TASKORIGIN[value];}},
		           {header:'完成情况',dataIndex:'TASKEXESTATUS',renderer:function(value){return OMS.TASKFINISHSTATE[value];}}],
   		listeners : {
   			rowdblclick : function(grid,rowIndex,e){
   				twi.initTaskWatchInfo(grid.store.getAt(rowIndex).data);
   			}
   		},
   		bbar : [{xtype:'paging',
   				 pageSize : 15,
   				 emptyMsg : '没有符合条件的数据，请重新搜索',
   				 displayInfo : true,
   				 store : this.taskStore}]
	});
	this.main_panel = new Ext.Panel({
		renderTo : 'main',
		title : '任务监控',
		width : '1020',
		items : [this.search_form,this.taskGrid]
	});
	this.init = function(expiredTask) {	
		this.getDept.load({});
		this.getDeptForExecutor.load({});
		if(expiredTask){
			this.expiredTask=expiredTask;
		this.taskStore.load();
		}
	};
};